<template>
	<view class="content">
	<view class="m-top">
			<view class="txt">
				开启机器人需要API交易权限
			</view>
			<view class="txt1">
				获取到火币的API Key；用于同步持仓和交易数据
				输入或复制粘贴你的API Key
			</view>
		</view>
		<view class="item-list">
			<view class="txt2">
				API Key
			</view>
			<view class="flex">
				<u-input v-model="api_key" :border="false"  placeholder="请输入API Key"/>
			</view>
		</view>
		
		<view class="item-list">
			<view class="txt2">
				Secret Key
			</view>
			<view class="flex">
				<u-input v-model="secret_key" :border="false"  placeholder="请输入Secret Key"/>
			</view>
		</view>
		<view class="btn-bottom" @click="submit">
			导入
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				api_key:'',
				secret_key:'',
				type:1,
				id:'',
			}
		},
		onLoad(e) {
			console.log('当前路由参数---------',e)
			if(e.type){
				this.type = e.type
			}
			if(e.id){
				this.id = e.id
			}
			
		},
		methods: {
			// 点击导入
			submit(){
				if(!this.api_key){
					uni.showToast({
					    title: 'API Key格式不正确',
					    duration: 1000,
						icon:'none'
					});
					return
				}
				if(!this.secret_key){
					uni.showToast({
					    title: 'Secret Key格式不正确',
					    duration: 1000,
						icon:'none'
					});
					return
				}
				let data = {
					api_key : this.api_key,
					secret_key: this.secret_key
				}
				if(this.type == 1){
					data.trade_id=this.id
				}else{
					data.id = this.id
				}
				this._submit(data)
			},
			_submit(e){
				this.$http({
					url:this.type==1?this.$api.bindTrade:`${this.$api.bindTrade}/${this.id}`,
					method:this.type==1?'POST':'PUT',
					hideLoading:true,
					debug:true,
					data:e,
					success:res=>{
						console.log('接口返回----------',res)
						if(res.code==201){
							uni.showToast({
							    title: res.msg,
							    duration: 2000,
								icon:'none'
							});
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
						}
					},
					fail:err=>{
						
					},complete:e=>{
						uni.hideLoading();
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background: #fff;
		padding-top:20rpx
		
	}
.m-top{
	font-weight: 600;
	color: #131415;
	line-height: 40rpx;
	border-bottom: 1px solid #F8F8F8;
	width: 100%;
	padding: 32rpx;
	display: flex;
	justify-content: center;
	flex-direction: column;
	align-items: flex-start;
	
}
.item-list{
	height: 160rpx;
	border-bottom: 1px solid #F8F8F8;
	text-align: left;
	    padding: 0 24rpx;
		width: 100%;
}
.txt{
	font-size: 28rpx;
}
.txt1{
	margin-top: 24rpx;
	font-size: 24rpx;
}

.txt2{
	font-size: 28rpx;
	font-weight: 600;
	color: #131415;
	line-height: 40px;
}
.flex{
	display: flex;
	justify-content:space-between;
	align-items: center;
}
	.btn-bottom{
			width: 694rpx;
			height: 80rpx;
			background: #2F73FD;
			box-shadow: 0px 4px 8px 0px rgba(166,196,255,1);
			border-radius: 40rpx;
			text-align: center;
			line-height: 80rpx;
			color: #fff;
			font-size: 32rpx;
			margin-top: 50rpx;
		}
</style>
